package com.lxy.mychat.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.lxy.mychat.Bean.User;
import com.lxy.mychat.R;

import java.util.List;

public class UserAdapter extends ArrayAdapter<User> {

    int resourceid;

    public UserAdapter(@NonNull Context context, int resource, @NonNull List<User> objects) {
        super(context, resource, objects);
        resourceid=resource;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent){
        View v=view;
        if (v==null){
            v= LayoutInflater.from(getContext()).inflate(resourceid,null);
        }
        ImageView userimg=v.findViewById(R.id.userimg);
        TextView usntxt=v.findViewById(R.id.usntxt);
        User u=getItem(position);
        userimg.setImageResource(u.getUserimg());
        usntxt.setText(u.getName());
        return v;
    }
}
